package Top200;

/**
 * @author zhangmin
 * @create 2022-02-18 9:59
 * 1、提前写好个十百千为的所有情况，num最大为3999
 * 2、按照每次取能取到的最大值
 */
public class intToRoman12 {
    String[] th={"","M","MM","MMM"};
    String[] hu={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
    String[] te={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
    String[] on={"","I","II","III","IV","V","VI","VII","VIII","IX"};

    public String intToRoman1(int num) {
        return th[num/1000]+hu[num%1000/100]+te[num%100/10]+on[num%10];
    }
    int[] val={1000,900,500,400,100,90,50,40,10,9,5,4,1};
    String[] sym={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
    public String intToRoman(int num) {
        StringBuffer sb=new StringBuffer();
        for (int i = 0; i < val.length; i++) {
            while (num>=val[i]){
                num-=val[i];
                sb.append(sym[i]);
            }
            if (num==0){
                break;
            }
        }
        return sb.toString();
    }
}
